<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Template plugin example</title>
<!-- TinyMCE -->
<script language="javascript" type="text/javascript" src="../jscripts/tiny_mce/tiny_mce_dev.js"></script>
<script language="javascript" type="text/javascript">
	function exampleTemplateFunction(elm) {
		elm.innerHTML = prompt("Please enter your favourite colour.", "Color");
	}

	var Invoice = {
		calculate : function(table) {
			var _n = function(s) {
				var n = parseFloat(s.replace(/[^-\d\.]/g,''));
				return isNaN(n) ? 0 : n;
			}

			var total = 0;
			var r = table.tBodies[0].rows;

			for(var x = 0; x < r.length; x++) {
				var c = r[x].cells;
				var t = _n(c[1].innerHTML)*_n(c[2].innerHTML);
				total += t;
				c[3].innerHTML = '$' + t; 
			}

			table.tFoot.rows[0].cells[1].innerHTML = '$' + total;
		}
	}

	var WordCount = {
		getText : function() {
			var inst = tinyMCE.selectedInstance;
			var na = [];
			tinyMCE.getNodeTree(inst.getBody(), na, 3);
			for(var x = 0; x < na.length; x++) {
				if(na[x].nodeValue && na[x].nodeValue.length > 3) {
					na[x] = na[x].nodeValue;
				} else {
					na[x] = '';
				}
			}
			return na.join('');
		},

		count : function(elm) {
			var s = WordCount.getText();
			elm.innerHTML = '' + s.split(' ').length;
		},

		charCount : function(elm) {
			var s = WordCount.getText();
			elm.innerHTML = '' + s.length;
		}
	}

	tinyMCE.init({
		mode : "textareas",
		theme : "advanced",
		plugins : "devkit,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
		theme_advanced_buttons1_add_before : "save,newdocument,separator",
		theme_advanced_buttons1_add : "fontselect,fontsizeselect",
		theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,separator,forecolor,backcolor,advsearchreplace",
		theme_advanced_buttons2_add_before: "cut,copy,paste,pastetext,pasteword,separator,search,replace,separator",
		theme_advanced_buttons3_add_before : "tablecontrols,separator",
		theme_advanced_buttons3_add : "emotions,iespell,media,advhr,separator,print,separator,ltr,rtl,separator,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,|,visualchars,nonbreaking,|,template,|,code",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_path_location : "bottom",
		content_css : "example_full.css",
	    plugin_insertdate_dateFormat : "%Y-%m-%d",
	    plugin_insertdate_timeFormat : "%H:%M:%S",
		extended_valid_elements : "hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style|title|tsrc],*[mcetmpldtesrc]",
		external_link_list_url : "example_link_list.js",
		external_image_list_url : "example_image_list.js",
		flash_external_list_url : "example_flash_list.js",
		media_external_list_url : "example_media_list.js",
		file_browser_callback : "fileBrowserCallBack",
		theme_advanced_resize_horizontal : false,
		theme_advanced_resizing : true,
		nonbreaking_force_tab : true,
		apply_source_formatting : true,
		template_cdate_classes : "cdate creationdate",
		template_mdate_classes : "mdate somedate",
		template_selected_content_classes : "selcontent",
		template_cdate_format : "%m/%d/%Y : %H:%M:%S",
		template_mdate_format : "%m/%d/%Y : %H:%M:%S",
		template_replace_values : {
			username : "Andrew Tetlaw",
			"invoice-items" : Invoice.calculate,
			"word-count" : WordCount.count,
			"char-count" : WordCount.charCount
		},
		template_templates : [
			{
				title : 'Editing Details',
				src : 'templates/editing_details.htm',
				description : "Timestamps, editor's name and a comment area"
			},
			{
				title : 'Invoice Template',
				src : 'templates/invoice.htm',
				description : 'Fill in the rows and the totals are calculated automatically'
			},
			{
				title : 'Word Count',
				src : 'templates/count.htm',
				description : 'Word count for editor content'
			},
			{
				title : 'Editors Comment',
				src : 'templates/editors_comment.htm',
				description : 'Add a comment about the selected text'
			}
		]
	});
	

</script>
<!-- /TinyMCE -->
</head>
<body>

<a href="example_full.htm">[Full featured example]</a> <a href="example_advanced.htm">[Advanced example]</a> <a href="example_simple.htm">[Simple example]</a>  <a href="example_word.htm">[Word example]</a>
<form method="get" action="">
	<h3>Template example</h3>
	This example shows how to make more advanced templates that execute logic.<br /><br />
	<textarea id="elm1" name="elm1" rows="15" cols="80" style="width: 100%">
		&lt;span class=&quot;example1&quot;&gt;Test header 1&lt;/span&gt;&lt;br /&gt;
		&lt;span class=&quot;example2&quot;&gt;Test header 2&lt;/span&gt;&lt;br /&gt;
		&lt;span class=&quot;example3&quot;&gt;Test header 3&lt;/span&gt;&lt;br /&gt;
		Some &lt;b&gt;element&lt;/b&gt;, this is to be editor 1. &lt;br /&gt; This editor instance has a 100% width to it.
		&lt;p&gt;Some paragraph. &lt;a href=&quot;http://www.sourceforge.net&quot;&gt;Some link&lt;/a&gt;&lt;/p&gt;
		&lt;img src=&quot;logo.jpg&quot;&gt;
	</textarea>
	<br />
	<input type="submit" name="save" value="Submit" />
	<input type="reset" name="reset" value="Reset" />
</form>

</body>
</html>

